package com.demo;
import com.methods.Animal;
import com.methods.Cat;
import com.methods.Dog;
import com.methods.Sheep;
import java.util.Random;

/**
 * 测试用例
 * 描述：利用随机种子生成不同的对象,并存入相应的对象数组
 * 2017/8/19.
 * @author Erik
 * @version 0.1
 * @since JDK1.8
 * @see com.methods.Cat
 * @see com.methods.Animal
 * @see com.methods.Sheep
 * @see com.methods.Dog
 */
public class Test {
    public static void main(String[] args){
        //对象数组
        Animal[] animals=new Animal[5];

        for(int i=0;i<animals.length;i++) {
            //TODO 产生随机数
            //每进行一次迭代，产生一个随机数
            Random random=new Random();
            int seed=random.nextInt(3);

            switch (seed) {
                case 0:
                    Cat cat = Cat.getCat();
                    animals[i]=cat;
                    break;
                case 1:
                    Dog dog = Dog.getDog();
                    animals[i]=dog;
                    break;
                case 2:
                    Sheep sheep = Sheep.getSheep();
                    animals[i]=sheep;
                    break;
                default:
                    System.out.println();
                    break;
            }

        }

        for (Animal animal : animals) {
            animal.cry();
        }

    }
}
